/**
 *
 * @param { * } value 需要处理的数字
 * @param { * } bedeck 是否显示+-
 */
function integral (value, bedeck) {
  let string = value
  if (string === 0) {
    return `0.00`
  } else {
    let abs = Number(string) < 0 ? '' : '+'
    let bdk = bedeck ? abs : ''
    let str = String(string)
    let reg = /([0-9])(?=(?:[0-9]{3})+$)/g
    if (str.indexOf('.') === -1) {
      return bdk + str.replace(reg, '$1,') + '.00'
    } else {
      let strArr = str.split('.')
      let end = strArr[1].length === 1 ? strArr[1] + '0' : strArr[1].substring(0, 2)
      return bdk + strArr[0].replace(reg, '$1,') + '.' + end
    }
  }
}

function Appendzero (obj) {
  if (obj < 10) return '0' + '' + obj
  else return obj
}

export default {
  filters: {
    // 处理金额数据
    integral: (value, bedeck = true) => {
      return integral(value, bedeck)
    },
    // 处理数字相加精度缺失问题
    addNumer: (value, ...values) => {
      values.push(value)
      let maxArr = []
      for (let item of values) {
        try {
          maxArr.push(String(item).split('.')[1].length)
        } catch (err) {
          maxArr.push(0)
        }
      }
      let max = Math.max(...maxArr)
      let num = max === 0 ? 1 : 10 ** (max - 1)
      let arr = values.map(value => {
        return Math.floor(value * num)
      })
      let count = 0
      for (let value of arr) {
        count += value
      }
      return integral(count / num)
    },
    date (data) {
      if (data === '' && typeof data === 'undefined') return
      let date = new Date(Number(data) * 1000)
      let Y = date.getFullYear() + '-'
      let M =
        (date.getMonth() + 1 < 10
          ? '0' + (date.getMonth() + 1)
          : date.getMonth() + 1) + '-'
      let D = date.getDate()
      let h = date.getHours() + ':'
      let m = date.getMinutes()
      return `${Y + M + D}  ${Appendzero(h)} ${Appendzero(m)}`
    }
  },
  directives: {
    // 取消浏览器保存密码
    passwrod: {
      bind: (el) => {
        el.children[0].setAttribute('type', 'password')
      }
    }
  }
}

















{
  "workbench.colorTheme": "Default Light+",
  "editor.fontSize": 15,
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  // // prettier:每行在这个字符数内整合代码，如果你的屏幕较宽分辨率较高可以适当加大
  "prettier.printWidth": 120,
  // // prettier:是否在每行末尾加上分号
  "prettier.semi": false,
  // // prettier:如果为true，将使用单行否则使用双引号
  "prettier.singleQuote": true,
  // // vetur:对html的内容使用js-beautify-html

  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "vue",
      "autoFix": true
    }
  ],
  "eslint.autoFixOnSave": true,
  "vetur.format.defaultFormatter.html": "prettier",
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
  "editor.tabSize": 2,
  "terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
  "git.autofetch": true,
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "vsicons.projectDetection.disableDetect": true,
  "editor.fontFamily": "monospace,Consolas, 'Courier New',",
  "editor.fontLigatures": true,
  "workbench.iconTheme": "vscode-icons",
  "editor.fontWeight": "700"
}
